﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CLVisionIOCardNC620.IOCardDevice
{
    public abstract class IOCardE16DeviceBase : IIOCardDevice
    {
        public abstract int nCurCardID { get; set; }
        public abstract string SerialNumber { get; set; }
        public abstract string TypeName { get; set; }
        public abstract bool IsOpen { get; set; }
        public abstract int IOCardInputBits { get; }
        public abstract int IOCardOutputBits { get; }
        public abstract int IOCardBits { get; }
        public Mutex Mutex { get; set; }
     //   public string DisplayName { set; get; }

        // IO卡类型枚举
        // 打开IO设备
        public abstract bool OpenIODevice(int CardID, out int ErrorCode, out string ErrorText);
        // 关闭IO设备
        public abstract bool CloseIODevice(int CardID, out int ErrorCode, out string ErrorText);

        // 设置DO
        public abstract bool SetOutPutData(int CardID, long OutPutData, out int ErrorCode, out string ErrorText);
        // 获取DO
        public abstract bool GetOutPutData(int CardID, out long OutPutData, out int ErrorCode, out string ErrorText);
        // 获取DI
        public abstract bool GetInPutData(int CardID, out long InPutData, out int ErrorCode, out string ErrorTextred);
        // 设置DO Bit位
        public abstract bool WriteOutPutBit(int CardID, int PortBit, int Value, out int ErrorCode, out string ErrorText);
        // 获取DO Bit位
        public abstract bool ReadOutPutBit(int CardID, int PortBit, out int Value, out int ErrorCode, out string ErrorText);
        // 获取DI Bit位
        public abstract bool ReadInPutbit(int CardID, int PortBit, out int Value, out int ErrorCode, out string ErrorText);


      
        public abstract void Release(int CardID, out int ErrorCode, out string ErrorText);
      

        // Binary二进制倒序
        public string InvertBinaryString(string binary, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "";
            char[] invertedChars = new char[binary.Length];
            for (int i = 0; i < binary.Length; i++)
            {
                if (binary[i] == '0')
                {
                    invertedChars[i] = '1';
                }
                else if (binary[i] == '1')
                {
                    invertedChars[i] = '0';
                }
            }
            return new string(invertedChars);
        }

        // Binary二进制按位取反
        public string ReverseBinaryString(string binary, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "";
            char[] charArray = binary.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

        public abstract void InterruptFun();
        public abstract bool GetCardVersion(int CardID, ref long VerNumber, out int ErrorCode, out string ErrorText);
        public abstract bool SetInterruptEnable(int CardID, int Enable, out int ErrorCode, out string ErrorText);
    }
}
